<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>

<button onclick="copy(8888)">EEEEEEEEEEEE</button>

<p  id="contentText1"></p>

<script>
    function copy(c) {
        document.querySelector("#contentText1").innerText=c;
        const copyEle = document.querySelector('#contentText1') // 获取要复制的节点
        const range = document.createRange(); // 创造range
        window.getSelection().removeAllRanges(); //清除页面中已有的selection
        range.selectNode(copyEle); // 选中需要复制的节点
        window.getSelection().addRange(range); // 执行选中元素
        const copyStatus = document.execCommand("Copy"); // 执行copy操作
        document.querySelector("#contentText1").innerText=""
        // 对成功与否定进行提示
        if (copyStatus) {
            //alert('复制成功');
        } else {
            // alert('复制失败');
        }
        window.getSelection().removeAllRanges(); //清除页面中已有的selection
    }
</script>
</body>
</html>